package org.zhs.linear;

import org.zhs.linear.MyLinkedList;

import java.util.Iterator;
import java.util.LinkedList;

/**
 * @Author: zhs
 * @Date: 2024/5/1 08:35
 * @Version: 1.0
 * @Description:
 */
public class Demo_MyLinkedList {

    public static void main(String[] args) {
        MyLinkedList<Integer> myLinkedList = new MyLinkedList<Integer>();
        for (int i = 1; i <= 10; i++) {
            myLinkedList.add(i);
        }
        System.out.println("初始化完成");
        System.out.println(myLinkedList);

        System.out.println("===========================================================");
        System.out.println("获取下标为5的元素:" + myLinkedList.get(5));

        System.out.println("===========================================================");
        System.out.println("初始化完成后的头节点:" + myLinkedList.getFirst());
        myLinkedList.removeFirst();
        System.out.println("移除头节点后的头节点:" + myLinkedList.getFirst());

        System.out.println("===========================================================");
        System.out.println("初始化完成后的尾节点:" + myLinkedList.getLast());
        myLinkedList.removeLast();
        System.out.println("移除尾节点后的尾节点:" + myLinkedList.getLast());

        System.out.println("===========================================================");
        System.out.println("实现foreach方法后的输出");
        myLinkedList.foreach(item -> {
            System.out.print(item +",");
        });
        System.out.println();

        System.out.println("===========================================================");
        System.out.println("实现迭代器后的输出");
        Iterator<Integer> iterator = myLinkedList.iterator();
        while (iterator.hasNext()){
            Integer next = iterator.next();
            System.out.print(next + ",");
        }
        System.out.println();


    }


}
